#include<iostream>
#include<vector>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;

namespace bit

{
    template <class T, class Container = vector<T>, class Compare = less<T> >

    class priority_queue

    {

    public:

        priority_queue()
        {}

        template <class InputIterator>

        priority_queue(InputIterator first, InputIterator last)
        {
            while (first != last)
            {
                push(*first);
                ++first;
            }
        }

        template<class T>
        struct less
        {
            bool operator()(const T& x, const T& y)
            {
                return x > y;
            }
        };

        template<class T>
        struct greater
        {
            bool operator()(const T& x, const T& y)
            {
                return x < y;
            }
        };

        bool empty() const
        {
            return _con.empty();
        }

        size_t size() const
        {
            return _con.size();
        }

        T& top() const
        {
            return _con[0];
        }

        void push(const T& x)
        {
            _con.push_back(x);
            adjust_up(_con.size() - 1);
        }

        void adjust_up(size_t child)
        {
            Compare com;
            size_t parent = (child - 1) / 2;
            while (child > 0)
            {
                if (com(_con[child] , _con[parent]))
                {
                    swap(_con[child], _con[parent]);
                    child = parent;
                    parent = (child - 1) / 2;
                }
                else
                {
                    break;
                }
            }
        }

        void pop()
        {
            swap(_con.size() - 1, _con[0]);
            _con.pop_back();
            adjust_down(0);
        }

        void adjust_down(size_t parent)
        {
            Compare com;
            size_t child = parent * 2 + 1;
            while (child < _con.size())
            {
                if (child + 1 < _con.size() && com(_con[child],_con[child + 1]))
                {
                    child++;
                }
                if (com(_con[child] , _con[parent]))
                {
                    swap(_con[parent], _con[child]);
                    parent = child;
                    child = parent * 2 + 1;
                }
                else
                {
                    break;
                }
            }
        }

    private:

        Container _con;

        Compare com;

    };

};